package com.kancy.springcloudconfig.util;

import com.kancy.springcloudconfig.util.service.CipherHolder;
import com.kancy.springcloudconfig.util.service.CryptoService;

/**
 * @author kancy
 * @date 2020/1/19 12:58
 **/
public class KmsUtil {
    public static String decrypt(String id, String key, String data){
        CipherHolder cipherHolder = new CipherHolder();
        cipherHolder.populateSecretKey(id,key);
        CryptoService cryptoService = new CryptoService(cipherHolder);
        return new String(cryptoService.decodeAndDecrypt(data));
    }
    public static String encrypt(String id, String key, String data){
        CipherHolder cipherHolder = new CipherHolder();
        cipherHolder.populateSecretKey(id,key);
        CryptoService cryptoService = new CryptoService(cipherHolder);
        return cryptoService.encryptAndEncode(data.getBytes());
    }
}
